﻿@model Pulog.Models.Post
           
@{
    ViewBag.Title = ViewData.Model.title + " - " + Helper.BlogName + " : " + Helper.BlogDescription;
}

@section MainContent{
    <script type="text/javascript" src="../../Scripts/jquery.scrollTo-1.4.2-min.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            $("#submitComment").click(function() {
                if($('#AuthorName').val() ==  '')
                {
                    alert('Name is required');
                    return false;
                }
                if($('#AuthorEmail').val().indexOf('@@') < 0)
                {
                    alert('Invalid email address');
                    return false;
                }
                if($('#CommentContent').val() ==  '')
                {
                    alert('Content cannot be empty');
                    return false;
                }
                var c = $("form").serialize();
                $.ajax({
                    type: "POST",
                    data: c,
                    //dataType: "json",
                    url: "@Url.Content("~/Comments/Add/")",
                    success: function(response){
                        // clear commentParentID
                        $("#CommentParentID").val("");
                        // make submit comment form visible again
                        $("#submitCommentFieldset").removeClass("replyCommentFieldset");
                        $("#addComment").appendTo("#comments");
                        //
                        $('div.boxcomments').load("@Url.Content("~/Comments/ShowByPostID/")"+$('#PostID').val(),
                        function(responseText, textStatus, XMLHttpRequest){
                            if(response >= 0)
                            {
                                $(window).scrollTo('div#Comment'+response);
                                $('div#Comment'+response).effect("highlight", {}, 8000);
                            }
                        });
                        $("#CommentContent").attr("value",'');
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown){
                        //alert("An error occured, please try again.");
                        alert(XMLHttpRequest.responseText);
                    },
                    complete: function(XMLHttpRequest, textStatus){
                        $("#submitComment").removeAttr("disabled");
                        $("#submitComment").attr("value", "写好了，加上去");
                    }
                });
            });
            
            $("#submitComment").ajaxSend(function(r,s){  
                $(this).attr("disabled", "true");
                $(this).attr("value", "Submitting...Please wait...");
            })
        });
        function ReplyComment(commentID,numericID) {
            $("#addComment").appendTo(commentID);
            $("#CommentParentID").val(numericID);
            $("#submitCommentFieldset").attr("class", "replyCommentFieldset");
            return true;
        };
     </script>

    <article class="post">
        <h3><a href="/Posts/Show/@ViewData.Model.postID.ToString()">@ViewData.Model.title</a></h3>
        
        <footer class="postmeta">作者:@Model.User.userName 发表于:@ViewData.Model.pubTime.ToString("yyyy年MM月dd日") -- @Helper.GetDateDifference(ViewData.Model.pubTime) | 分类: <a href="/Category/@ViewData.Model.Category.categoryName">
            @ViewData.Model.Category.categoryName</a> | <a href="/Posts/Show/@Model.postID.ToString()#comments">Comments: @Model.Comments.Count</a> | Views: @Model.views | &nbsp; <!-- AddThis Button BEGIN -->
            <div class="addthis_toolbox addthis_default_style">
            <a href="http://www.addthis.com/bookmark.php?v=250&amp;username=starcub" class="addthis_button_compact">Share</a>
            </div>
            <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=starcub"></script>
            <!-- AddThis Button END -->
        </footer>

        <p>
            @MvcHtmlString.Create(ViewData.Model.content)
        </p>

        @if (Request.IsAuthenticated)
        { 
            <p>
                @Html.ActionLink("Edit", "Edit", new { id = Model.postID }) |
                @Html.ActionLink("Back to List", "Index")
            </p>
        }
    </article>
    <div id="comments">
        @{Html.RenderPartial("PostComments", Model);}
        @if (Model.property != 1)
        {
            <div id="addComment">
                @{Html.RenderPartial("_SubmitComment"); }
            </div>
        }
        else
        {
            <div id="noComment">
                <hr />
                <span>Commenting is disabled.</span>
            </div>
        } 
    </div>
}